<?php
    error_reporting(0);
    define('__ROOT__', dirname(dirname(__FILE__)));
    require_once(__ROOT__.'\config\config.php'); 
    require_once(__ROOT__.'\model\db.php');
    require_once(__ROOT__.'\model\products.php');
    require_once(__ROOT__.'\model\categories.php');
    require_once (__ROOT__.'\controller\pagination.php');
    $params = array(
        'offset' => isset($_GET['page']) ? (int) $_GET['page'] : 1
    );
    $category = new Categories();
    $product = new Products();
    $products = $product->selectALL($params);
    $total = $product->countproductALL();
?>
<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8"/>
	<title>Dashboard I Admin Panel</title>
	
	<link rel="stylesheet" href="../css/layout.css" type="text/css" media="screen" />
	<!--[if lt IE 9]>
	<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
	<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<script src="../js/jquery-1.5.2.min.js" type="text/javascript"></script>
	<script src="../js/hideshow.js" type="text/javascript"></script>
	<script src="../js/jquery.tablesorter.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../js/jquery.equalHeight.js"></script>
</head>


<body>
	<?php
            require_once(__ROOT__.'\view\admin_header.php'); 
        ?>
	
	<section id="main" class="column">
            <?php
                if(isset($_GET['action']))
                {
                    if($_GET['action'] == 'succeed')
                        echo '<h4 class="alert_success">Thành công</h4>';
                    if($_GET['action'] == 'fail')
                        echo '<h4 class="alert_error">Thất bại kiểm tra lại dữ liệu</h4>';
                }
            ?>
		<article class="module width_3_quarter">
		<header>
		<ul class="tabs">
                    <?php
                        $pagination = new Pagination();
                        $params = array_merge($params, array(
                            'current_page' => isset($_GET['page'])?$_GET['page']:1,
                            'total_page' => $total,
                            'file' => 'view_adminproduct.php'
                        ));
                        echo $pagination->display4($params);
                    ?>
		</ul>
		</header>
		<div class="tab_container">
			<div id="tab1" class="tab_content">
			<table class="tablesorter" cellspacing="0"> 
			<thead> 
				<tr> 
    				<th>Tên</th> 
    				<th>Giá</th> 
    				<th>Số Lượng</th>
                                <th>Loại</th> 
                                <th>Xác Nhận</th> 
				</tr> 
			</thead> 
                        <?php foreach($products as $productss): ?>
                        <?php
                            $categories = $category->get_name_by($productss['category']);           
                        ?>
                        <form method="POST" action="<?php echo HOST ?>controller/product_controller.php?id=<?php echo $productss['id'] ?>">
			<tbody>  
                                <tr> 		
                                    <td><?php echo $productss['name'] ?></td> 
                                    <td><?php echo number_format($productss['price'] , 0, ',', '.'); ?> Đồng</td> 
                                    <td><?php echo $productss['quantity'] ?></td>
                                    <td><?php echo $categories['name']  ?></td>  
                                    <td><input type="image" src="<?php echo HOST ?>images/admin/icn_edit.png" title="Sửa" name="edit">                       
                                            <input type="image" src="<?php echo HOST ?>images/admin/icn_alert_error.png" title="Xóa" name="delete">              
				</tr> 
			</tbody> 
                        </form>
                        <?php endforeach; ?>
			</table>
			</div>
		</div>
		
		</article>
	</section>


</body>

</html>